package com.example.demo.controller;


import com.example.demo.entity.Film;
import com.example.demo.entity.usecategory;
import com.example.demo.service.FilmService;
import com.example.demo.service.IusecategoryService;
import com.example.demo.util.JsonResult;
import net.minidev.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("port")
public class userController extends BaseController {

    @Autowired
    private IusecategoryService iusecategoryService;

    @Autowired
    private FilmService filmService;

    @RequestMapping("getUserConsumeServenDayCategory")
    public JsonResult<usecategory> getuse(Integer userId,HttpSession session){
        usecategory usecategory = iusecategoryService.getUseCategory(userId);
        session.setAttribute("userId",usecategory.getUserId());
        session.setAttribute("day",usecategory.getDay());
        session.setAttribute("category",usecategory.getCategory());

        return new JsonResult<>(OK,usecategory);
    }

    @RequestMapping("getUserServeDayCategoryMoney")
    public void getuseMoney(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ParseException {
        List<usecategory> list= iusecategoryService.getUseCategoryMoney();

        response.setContentType("application/json;charset=GBK");
        PrintWriter out = response.getWriter();
        String res = JSONArray.toJSONString(list);
        out.print(res);
        out.flush();
        out.close();
    }

    @RequestMapping("getAllFilmList")
    public void getFilm(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ParseException{
        List<Film> list = filmService.getFilm();
        response.setContentType("application/json;charset=GBK");
        PrintWriter out = response.getWriter();
        String res = JSONArray.toJSONString(list);
        out.print(res);
        out.flush();
        out.close();
    }






}


